home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWEmbUtl.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  7.6 KB  |  265 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWEmbUtl.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWEMBUTL_H
  13. #include "FWEmbUtl.h"
  14. #endif
  15.  
  16. #ifndef FWFILESP_H
  17. #include "FWFileSp.h"
  18. #endif
  19.  
  20. #ifndef FWACQUIR_H
  21. #include "FWAcquir.h"
  22. #endif
  23.  
  24. #ifndef FWBARRAY_H
  25. #include "FWBArray.h"
  26. #endif
  27.  
  28. #ifndef FWCLNINF_H
  29. #include "FWClnInf.h"
  30. #endif
  31.  
  32. #ifndef FWFRAME_H
  33. #include "FWFrame.h"
  34. #endif
  35.  
  36. #ifndef FWINTER_H
  37. #include "FWInter.h"
  38. #endif
  39.  
  40. #ifndef SLODFSTR_K
  41. #include "SLODFStr.k"
  42. #endif
  43.  
  44. #ifndef SLODFSTR_H
  45. #include "SLODFStr.h"
  46. #endif
  47.  
  48. #ifndef FWALERT_H
  49. #include "FWAlert.h"
  50. #endif
  51.  
  52. #ifndef FWSESION_H
  53. #include "FWSesion.h"
  54. #endif
  55.  
  56. // ----- OpenDoc Includes -----
  57.  
  58. #ifndef SOM_ODDraft_xh
  59. #include <Draft.xh>
  60. #endif
  61.  
  62. #ifndef SOM_ODDraft_xh
  63. #include <Draft.xh>
  64. #endif
  65.  
  66. #ifndef SOM_ODDocument_xh
  67. #include <Document.xh>
  68. #endif
  69.  
  70. #ifndef SOM_ODStorageSystem_xh
  71. #include <ODStor.xh>
  72. #endif
  73.  
  74. #ifndef SOM_Module_OpenDoc_StdProps_defined
  75. #include <StdProps.xh>
  76. #endif
  77.  
  78. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  79. #include <StdTypes.xh>
  80. #endif
  81.  
  82. //========================================================================================
  83. //    Runtime Info
  84. //========================================================================================
  85.  
  86. #ifdef FW_BUILD_MAC
  87. #pragma segment fw_embedding
  88. #endif
  89.  
  90. //========================================================================================
  91. //    Global Methods
  92. //========================================================================================
  93.  
  94. //----------------------------------------------------------------------------------------
  95. // FW_AcquireFileContainer
  96. //----------------------------------------------------------------------------------------
  97.  
  98. ODContainer* FW_AcquireFileContainer(Environment* ev, const FW_PFileSpecification& fileSpec)
  99. {
  100. #ifdef FW_BUILD_MAC
  101.     FSSpec macSpec;
  102.     fileSpec->MacGetFSSpec(ev, &macSpec);
  103.  
  104.     FW_CByteArray bArray(&macSpec, sizeof(short) + sizeof(long) + macSpec.name[0] + 1);
  105.     return FW_CSession::GetStorageSystem(ev)->AcquireContainer(ev, kODDefaultFileContainer, bArray);
  106. #endif
  107.  
  108. #ifdef FW_BUILD_WIN
  109.     FW_DEBUG_MESSAGE("Not Yet Implemented");    
  110. #endif
  111. }
  112.     
  113. //----------------------------------------------------------------------------------------
  114. //    FW_InsertPartFromFile
  115. //----------------------------------------------------------------------------------------
  116.  
  117. FW_EInternalizeResult FW_InsertPartFromFile(Environment* ev, 
  118.                                             FW_CEmbeddingFrame* frame, 
  119.                                             const FW_PFileSpecification& fileSpec)
  120. {
  121.     FW_EInternalizeResult result = FW_kInternalizeFailed;
  122.  
  123.     FW_CAcquiredODContainer aqContainer = ::FW_AcquireFileContainer(ev, fileSpec);
  124.     if (aqContainer != NULL)
  125.     {
  126.         // ----- Get the document -----
  127.         FW_CAcquiredODDocument documentToInsert = aqContainer->AcquireDocument(ev, kODDefaultDocument);
  128. /*        
  129.         //     [HLX] There is no way to test that I am trying to insert the same document. The following code
  130.         //    doesn't work. 
  131.         
  132.         // ----- Check we are not trying to insert itself -----
  133.         ODID id1 = frame->GetPart(ev)->GetDraft(ev)->GetDocument(ev)->GetID(ev);
  134.         ODID id2 = documentToInsert->GetID(ev);
  135.         if (id2 == id1)
  136.         {
  137.             FW_CString errorStr;
  138.             FW_CString32 partName;
  139.             frame->GetPart(ev)->GetPartName(ev, partName);
  140.             FW_PrivLoadODFString(ev, FW_kInsertSameDocument, errorStr);
  141.             FW_ErrorAlert(partName, errorStr);
  142.             return result;
  143.         }
  144. */        
  145.         // ----- Get the draft -----
  146.         FW_CAcquiredODDraft fromDraft = documentToInsert->AcquireBaseDraft(ev, kODDPReadOnly);
  147.         
  148.         while (documentToInsert->Exists(ev, 0, fromDraft, kODPosLastAbove))
  149.         {
  150.             fromDraft = documentToInsert->AcquireDraft(ev, 
  151.                                                         kODDPReadOnly,
  152.                                                         NULL, 
  153.                                                         fromDraft, 
  154.                                                         kODPosLastAbove,
  155.                                                         FALSE);
  156.         }
  157.  
  158.         FW_CAcquiredODStorageUnit fromSU = fromDraft->AcquireDraftProperties(ev);
  159.  
  160.         fromSU->Focus(ev, kODPropRootPartSU, kODPosUndefined, kODStrongStorageUnitRef, 0, kODPosUndefined);
  161.         
  162.         ODStorageUnitRef aSURef;
  163.         FW_CByteArray byteArray; 
  164.         fromSU->GetValue(ev, sizeof(aSURef), byteArray);
  165.         byteArray.CopyBuffer( &aSURef, sizeof(aSURef));
  166.  
  167.         FW_CAcquiredODStorageUnit aqInsertSU = fromDraft->AcquireStorageUnit(ev, fromSU->GetIDFromStorageUnitRef(ev, aSURef));
  168.         
  169.         FW_CPresentation* presentation = frame->GetPresentation(ev);
  170.         
  171.         // ----- Embed -----
  172.         ODPasteAsResult embedInfo;
  173.         
  174.         embedInfo.pasteLinkSetting     = FALSE;
  175.         embedInfo.autoUpdateSetting = FALSE;
  176.         embedInfo.mergeSetting         = FALSE;
  177.         embedInfo.selectedView         = presentation->GetDefaultEmbeddedFrameViewType(ev);
  178.         embedInfo.selectedKind         = NULL;
  179.         embedInfo.translateKind     = NULL;
  180.         embedInfo.editor             = kODNoEditor;
  181.  
  182.         FW_CPart* part = presentation->GetPart(ev);
  183.         FW_CSelection* selection = presentation->GetSelection(ev);
  184.         result = part->GetDataInterchange(ev)->InternalizeData(ev, selection->GetSelectedContent(ev), frame, aqInsertSU, FW_kFileStorage, kODClonePaste, &embedInfo);
  185.     }
  186.     
  187.     return result;
  188. }
  189.  
  190. //----------------------------------------------------------------------------------------
  191. //    FW_ClonePartFromFile
  192. //----------------------------------------------------------------------------------------
  193.  
  194. ODPart* FW_ClonePartFromFile(Environment* ev, FW_CEmbeddingFrame* scopeFrame, const FW_PFileSpecification& fileSpec)
  195. {
  196.     FW_ASSERT(scopeFrame);
  197.     
  198.     ODDraft* destDraft = scopeFrame->GetPart(ev)->GetDraft(ev);
  199.  
  200.     ODPart* clonedPart = NULL;
  201.  
  202.     FW_CAcquiredODContainer aqContainer = ::FW_AcquireFileContainer(ev, fileSpec);
  203.     if (aqContainer != NULL)
  204.     {
  205.         // ----- Get the document -----
  206.         FW_CAcquiredODDocument documentToInsert = aqContainer->AcquireDocument(ev, kODDefaultDocument);
  207.  
  208.         // ----- Get the draft -----
  209.         FW_CAcquiredODDraft fromDraft = documentToInsert->AcquireBaseDraft(ev, kODDPReadOnly);
  210.         
  211.         while (documentToInsert->Exists(ev, 0, fromDraft, kODPosLastAbove))
  212.         {
  213.             fromDraft = documentToInsert->AcquireDraft(ev, 
  214.                                                         kODDPReadOnly,
  215.                                                         NULL, 
  216.                                                         fromDraft, 
  217.                                                         kODPosLastAbove,
  218.                                                         FALSE);
  219.         }
  220.  
  221.         FW_CAcquiredODStorageUnit fromSU = fromDraft->AcquireDraftProperties(ev);
  222.  
  223.         fromSU->Focus(ev, kODPropRootPartSU, kODPosUndefined, kODStrongStorageUnitRef, 0, kODPosUndefined);
  224.         
  225.         ODStorageUnitRef aSURef;
  226.         FW_CByteArray byteArray; 
  227.         fromSU->GetValue(ev, sizeof(aSURef), byteArray);
  228.         byteArray.CopyBuffer( &aSURef, sizeof(aSURef));
  229.  
  230.         FW_CAcquiredODStorageUnit aqInsertSU = fromDraft->AcquireStorageUnit(ev, fromSU->GetIDFromStorageUnitRef(ev, aSURef));
  231.         
  232.         FW_CCloneInfo cloneInfo(ev, fromDraft, scopeFrame, kODClonePaste);
  233.         cloneInfo.BeginClone(ev, destDraft);
  234.         
  235.         ODID clonedPartID = cloneInfo.Clone(ev, aqInsertSU->GetID(ev), 0, 0);
  236.         FW_ASSERT(clonedPartID != kODNULLID);
  237.  
  238.         cloneInfo.EndClone(ev);
  239.  
  240.         clonedPart = destDraft->AcquirePart(ev, clonedPartID);
  241.     }
  242.     
  243.     return clonedPart;
  244. }
  245.  
  246. #ifdef FW_BUILD_MAC
  247. //----------------------------------------------------------------------------------------
  248. //    FW_MacInsertFilterProc
  249. //----------------------------------------------------------------------------------------
  250.  
  251. pascal Boolean FW_MacInsertFilterProc(CInfoPBPtr pb)
  252. {
  253.     FInfo* finderInfo = &pb->hFileInfo.ioFlFndrInfo;
  254.     // remenber: TRUE suppresses display, FALSE allows display
  255. #if 0
  256.     return (finderInfo->fdCreator != 'odtm') ||             // otdm creator
  257.             ((finderInfo->fdFlags & 0xE000) != 0) ||        // visible 
  258.             (finderInfo->fdType == 'APPL');                    // Not an application
  259. #endif
  260.     return (((finderInfo->fdFlags & 0xE000) != 0) ||        // visible 
  261.             (finderInfo->fdType == 'APPL'));                    // Not an application
  262.  
  263. }
  264. #endif
  265.